package org.ring.common.transport;

import com.alibaba.com.caucho.hessian.io.Hessian2Input;
import com.alibaba.com.caucho.hessian.io.Hessian2Output;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @since 2024-07-15 20:34
 */
public class Hessian2Serialization implements Serialization {

    @Override
    public <T> void serialize(T obj, OutputStream output) throws IOException {
        Hessian2Output out = new Hessian2Output(output);
        out.writeObject(obj);
        out.flushBuffer();
    }

    @Override
    public <T> T deserialize(InputStream input) throws IOException {
        Hessian2Input in = new Hessian2Input(input);
        return (T) in.readObject();
    }
}
